package com.fizzkai.p2p.core.domain;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fizzkai.p2p.core.util.MaskUtil;
import lombok.Getter;
import lombok.Setter;

import java.util.HashMap;
import java.util.Map;

@Getter
@Setter
public class RealAuth extends BaseAuthDomain {
    public static final int SEX_MALE = 0;//性别男
    public static final int SEX_FEMALE = 1;//性别女

    private String realName;//真实姓名
    private int sex;//性别
    private String idNumber;//身份证号码
    private String bornDate;//出生年月
    private String address;//身份证地址
    private String image1;//身份证正面
    private String image2;//身份证反面

    public String getSexDisplay() {
        return sex == SEX_MALE ? "男" : "女";
    }

    public String getJsonString() throws Exception {
        Map<String, Object> map = new HashMap<>();
        map.put("id", getId());
        map.put("applierName", getApplier().getUsername());
        map.put("realName", realName);
        map.put("idNumber", idNumber);
        map.put("sex", getSexDisplay());
        map.put("bornDate", bornDate);
        map.put("address", address);
        map.put("image1", image1);
        map.put("image2", image2);
        String res = new ObjectMapper().writeValueAsString(map);
        return res;
    }

    public String getAnonymousRealName() {
        return MaskUtil.getAnonymousRealName(realName);
    }
    public String getAnonymousIdNumber() {
        return MaskUtil.getAnonymousIdNumber(idNumber);
    }
    public String getAnonymousAddress() {
        return MaskUtil.getAnonymousIdNumber(address);
    }

}
